<?php

function displayPageLinks($num_pets, $num_to_display, $starting_num, $pet_type, $isSpec)
{
	global $PHP_SELF;
	if ($num_pets > $num_to_display) 
	{

		echo("<CENTER>");
		if (empty($starting_num))
		{	// if this is our first page, then start at 0
			$starting_num=0;
		} //  end if

		if ($isSpec){
			$result = @mysql_query("SELECT * FROM cats, dogs
								WHERE pet_status='v' AND spec_need = 1
								LIMIT $starting_num,$num_to_display");
		}
		else{
			$result = @mysql_query("SELECT * FROM $pet_type
								WHERE pet_status='v'
								LIMIT $starting_num,$num_to_display");
		}
		
		$count =mysql_num_rows($result);  // how many we have for this page


		if ($starting_num!=0) //bypass PREV link if offset is 0
		{  
			$prevoffset=$starting_num-$num_to_display;
			print"<a href=\"$PHP_SELF?starting_num=$prevoffset\"><img src=\"images/backwrd1.gif\" border=0 alt=\"PREV\"></a>&nbsp; \n";
		}  // end if

		//calculate number of pages needing links
		$pages = intval($num_pets/$num_to_display);

		// $pages now contains int of pages needed unless there is a remainder from division
		if ($num_pets%$num_to_display) 
		{
			//has remainder so add one page
			$pages++;
		}  // end if


		for ($i=1;$i<=$pages;$i++) 
		{ 
			$newoffset=$num_to_display*($i-1);
			if ($newoffset == $starting_num):
				print "$i&nbsp; \n";
			else:
				print "<a href=\"$PHP_SELF?petType=$petType&starting_num=$newoffset\">$i</a>&nbsp; \n";
			endif;
		}	// end for

		// check to see if last page
		if (!( ( ($starting_num+$num_to_display) / $num_to_display) >= $pages) && $pages!=1) 
		{
			// not last page so give NEXT link
			$newoffset=$starting_num+$num_to_display;
			print "<a href=\"$PHP_SELF?petType=$petType&starting_num=$newoffset\"><img src=\"images/forward1.gif\" border=0 alt=\"NEXT\"></a></td></tr>";
		}  //end if

		if ( $pages >1) 
		{
			echo("<BR>More Companions<BR>");
		}  // end if

		echo("</CENTER>");
	}
}	  // end if ($num_pets > $num_to_display)
?>